﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Authors.ascx.cs"
   Inherits="Authors" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit"
   TagPrefix="act" %>
<asp:Panel runat="server" ID="AuthorSelectionWrapper" CssClass="AuthorSelectionWrapper"
   ForeColor="Black" DefaultButton="btSearch">
   <asp:Panel runat="server" ID="AuthPanContent" CssClass="AuthorSelectionContent">
      <asp:UpdatePanel ID="upSelectedAuthors" runat="server">
         <ContentTemplate>
            <asp:Label runat="server" ID="lblAuthors" Text="Authors" Width="150px"
               Style="vertical-align: top"></asp:Label>
            <asp:CheckBox runat="server" ID="chkbxAuthorMyself" Text="Include Myself"
               AutoPostBack="true" OnCheckedChanged="chkbxAuthorMyself_CheckedChanged" />
            <br />
            <asp:Panel runat="server" ID="panEnterUserName" Visible="false">
               <asp:TextBox runat="server" ID="tbFirstName" Text="First Name" Width="80"></asp:TextBox>
               <asp:TextBox runat="server" ID="tbMidName" Text="Middle Name" Width="80" />
               <asp:TextBox runat="server" ID="tbLastName" Text="Last Name" Width="80" />
               <asp:LinkButton runat="server" ID="lbSearchSelfName" Text="Search" ToolTip="Check if this name is already present in the system."
                  OnClick="lbSearchSelfName_Click" CausesValidation="false" ValidationGroup="None" />
               <asp:LinkButton runat="server" ID="lbCancelSelfSelection" Text="Clear"
                  ToolTip="Clear Selected Name" CausesValidation="false" ValidationGroup="None"
                  Visible="false" onclick="lbCancelSelfSelection_Click"/>
               <asp:Button ID="SubmitUserName" runat="server" 
                  oncommand="SubmitUserName_Command" Text="Submit" 
                  ValidationGroup="UserSelfName" />
               <br />
               <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
                  ControlToValidate="tbFirstName" Display="Dynamic" ErrorMessage="RequiredFieldValidator"
                  ValidationGroup="UserSelfName"><br />First Name must be present.</asp:RequiredFieldValidator>
               <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
                  ControlToValidate="tbLastName" Display="Dynamic" ErrorMessage="RequiredFieldValidator"
                  ValidationGroup="UserSelfName"><br />Last Name must be present.</asp:RequiredFieldValidator>
               <asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server"
                  ControlToValidate="tbFirstName" Display="Dynamic" ErrorMessage="RegularExpressionValidator"
                  ValidationExpression="[A-Z]\w+" ValidationGroup="UserSelfName"><br />First Name must be a single word starting from capital letter.</asp:RegularExpressionValidator>
               <asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server"
                  ControlToValidate="tbMidName" Display="Dynamic" ErrorMessage="RegularExpressionValidator"
                  ValidationExpression="[A-Z]\w+" ValidationGroup="UserSelfName"><br />Middle Name Should be a single word starting with capital letter.</asp:RegularExpressionValidator>
               <asp:RegularExpressionValidator ID="RegularExpressionValidator6" runat="server"
                  ControlToValidate="tbLastName" Display="Dynamic" ErrorMessage="RegularExpressionValidator"
                  ValidationExpression="[A-Z]\w+" ValidationGroup="UserSelfName"><br />Last Name must be single word starting with capital letter.</asp:RegularExpressionValidator>
            </asp:Panel>
            <asp:Panel runat="server" ID="panSearchSelfAuthor" Visible="false">
               <br />
               <asp:LinkButton runat="server" ID="lbSelfSearchCancel" Text="Cancel" CausesValidation="False"
                  CssClass="SearchBox" OnClick="lbSearchSelfNameCancel_Click"></asp:LinkButton>
               <br />
               <br />
               <asp:ListView ID="lvSelfNameSelection" runat="server" DataKeyNames="id"
                  DataSourceID="SearchSelfSQLDataSource">
                  <ItemTemplate>
                     <asp:Panel ID="Panel1" runat="server" CssClass="ItemTemplatePanel">
                        <asp:LinkButton runat="server" ID="lbAddAuthor" CommandName="AddSelfCommand"
                           CommandArgument='<%# Eval("id") %>' OnCommand="AddSelfButtonCommand"
                           Style="color: Black" Text='<%# ComposeFullName(Eval("authfn"),Eval("authmn"),Eval("authln")) %>'></asp:LinkButton>
                     </asp:Panel>
                  </ItemTemplate>
                  <AlternatingItemTemplate>
                     <asp:Panel ID="Panel2" runat="server" CssClass="ItemAlternateTemplatePanel">
                        <asp:LinkButton runat="server" ID="lbAddAuthor" CommandName="AddSelfCommand"
                           CommandArgument='<%# Eval("id") %>' OnCommand="AddSelfButtonCommand"
                           Style="color: Black" Text='<%# ComposeFullName(Eval("authfn"),Eval("authmn"),Eval("authln")) %>'></asp:LinkButton>
                     </asp:Panel>
                  </AlternatingItemTemplate>
                  <EmptyDataTemplate>
                     <table id="Table1" runat="server" style="background-color: #FFFFFF; border-collapse: collapse;
                        border-color: #999999; border-style: none; border-width: 1px;">
                        <tr>
                           <td>
                              <asp:Label runat="server" ID="EmptyDataLabel" Text="No result."></asp:Label>
                           </td>
                        </tr>
                     </table>
                  </EmptyDataTemplate>
                  <InsertItemTemplate>
                     <tr style="">
                        <td>
                           <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
                           <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
                        </td>
                        <td>
                           &nbsp;
                        </td>
                        <td>
                           <asp:TextBox ID="authfnTextBox" runat="server" Text='<%# Bind("authfn") %>' />
                        </td>
                        <td>
                           <asp:TextBox ID="authmnTextBox" runat="server" Text='<%# Bind("authmn") %>' />
                        </td>
                        <td>
                           <asp:TextBox ID="authlnTextBox" runat="server" Text='<%# Bind("authln") %>' />
                        </td>
                     </tr>
                  </InsertItemTemplate>
                  <LayoutTemplate>
                     <asp:Panel ID="itemPlaceholder" runat="server">
                     </asp:Panel>
                  </LayoutTemplate>
                  <EditItemTemplate>
                     <tr style="background-color: #999999;">
                        <td>
                           <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
                           <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
                        </td>
                        <td>
                           <asp:Label ID="idLabel1" runat="server" Text='<%# Eval("id") %>' />
                        </td>
                        <td>
                           <asp:TextBox ID="authfnTextBox" runat="server" Text='<%# Bind("authfn") %>' />
                        </td>
                        <td>
                           <asp:TextBox ID="authmnTextBox" runat="server" Text='<%# Bind("authmn") %>' />
                        </td>
                        <td>
                           <asp:TextBox ID="authlnTextBox" runat="server" Text='<%# Bind("authln") %>' />
                        </td>
                     </tr>
                  </EditItemTemplate>
                  <SelectedItemTemplate>
                     <tr style="background-color: #E2DED6; font-weight: bold; color: #333333;">
                        <td>
                           <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
                        </td>
                        <td>
                           <asp:Label ID="authfnLabel" runat="server" Text='<%# Eval("authfn") %>' />
                        </td>
                        <td>
                           <asp:Label ID="authmnLabel" runat="server" Text='<%# Eval("authmn") %>' />
                        </td>
                        <td>
                           <asp:Label ID="authlnLabel" runat="server" Text='<%# Eval("authln") %>' />
                        </td>
                     </tr>
                  </SelectedItemTemplate>
               </asp:ListView>
               <asp:SqlDataSource ID="SearchSelfSQLDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:NMRExperimentsConnectionString %>"
                  SelectCommand="SELECT        id, authfn, authmn, authln
FROM            authors
WHERE        (LEFT(authfn, @fnlen) = @fnsearchstr OR
                         @fnlen = 0) AND (LEFT(authmn, @mnlen) = @mnsearchstr OR
                         @mnlen = 0) AND (LEFT(authln, @lnlen) = @lnsearchstr OR
                         @lnlen = 0) AND (authun IS NULL)">
                  <SelectParameters>
                     <asp:Parameter DefaultValue="0" Name="fnlen" />
                     <asp:Parameter DefaultValue="0" Name="mnlen" />
                     <asp:Parameter DefaultValue="0" Name="lnlen" />
                     <asp:Parameter DefaultValue="&quot;&quot;" Name="fnsearchstr" />
                     <asp:Parameter DefaultValue="&quot;&quot;" Name="mnsearchstr" />
                     <asp:Parameter DefaultValue="&quot;&quot;" Name="lnsearchstr" />
                  </SelectParameters>
               </asp:SqlDataSource>
            </asp:Panel>
            <asp:Label runat="server" ID="lblSelectedAuthors"></asp:Label>
         </ContentTemplate>
         <Triggers>
         </Triggers>
      </asp:UpdatePanel>
      <asp:Panel ID="panAddNewAuthor" runat="server">
         <asp:Image ID="Image" CssClass="AddButton" runat="server" />
      </asp:Panel>
      <asp:Panel ID="panSelectAuthor" runat="server">
         <asp:UpdatePanel ID="uppanAddAuthors" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
               <asp:Panel runat="server" ID="panAddAuthor" Visible="false" DefaultButton="btCreateNewAuthor">
                  <br />
                  <asp:TextBox runat="server" Width="80px" ID="tbNewFN"></asp:TextBox>
                  <asp:TextBox runat="server" Width="80px" ID="tbNewMN"></asp:TextBox>
                  <asp:TextBox runat="server" Width="80px" ID="tbNewLN"></asp:TextBox>
                  <asp:Button runat="server" ID="btCreateNewAuthor" ValidationGroup="NewUserSelfName"
                     Text="Submit" OnCommand="CreateNewAuthorButton_Command" />
                  <asp:LinkButton runat="server" ID="lbtCancelNewAuthor" Text="Cancel" CausesValidation="false"
                     OnClick="CancelNewAuthor_Command" />
                  <br />
                  <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                     ControlToValidate="tbNewFN" Display="Dynamic" ErrorMessage="RequiredFieldValidator"
                     ValidationGroup="NewUserSelfName"><br />First Name must be present.</asp:RequiredFieldValidator>
                  <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
                     ControlToValidate="tbNewLN" Display="Dynamic" ErrorMessage="RequiredFieldValidator"
                     ValidationGroup="NewUserSelfName"><br />Last Name must be present.</asp:RequiredFieldValidator>
                  <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
                     ControlToValidate="tbNewFN" Display="Dynamic" ErrorMessage="RegularExpressionValidator"
                     ValidationExpression="[A-Z]\w+" ValidationGroup="NewUserSelfName"><br />First Name must be a single word starting from capital letter.</asp:RegularExpressionValidator>
                  <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
                     ControlToValidate="tbNewMN" Display="Dynamic" ErrorMessage="RegularExpressionValidator"
                     ValidationExpression="[A-Z]\w+" ValidationGroup="NewUserSelfName"><br />Middle Name Should be a single word starting with capital letter.</asp:RegularExpressionValidator>
                  <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server"
                     ControlToValidate="tbNewLN" Display="Dynamic" ErrorMessage="RegularExpressionValidator"
                     ValidationExpression="[A-Z]\w+" ValidationGroup="NewUserSelfName"><br />Last Name must be single word starting with capital letter.</asp:RegularExpressionValidator>
               </asp:Panel>
               <asp:Panel runat="server" ID="panWrapper">
                  <br />
                  <asp:TextBox runat="server" Width="200px" ID="tbSearch" CssClass="SearchBox"></asp:TextBox>
                  <asp:Button runat="server" ID="btSearch" Text="Search" CausesValidation="false" 
                     OnCommand="SearchButton_Command" 
                     ToolTip="You will not find yourself. Use checkbox on above." />
                  <asp:LinkButton runat="server" ID="lbtFormCreateNew" Text="Create New" CausesValidation="false"
                     OnClick="lbtFormCreateNew_Click"></asp:LinkButton>
                  <br />
                  <asp:ListView ID="lvAuthors" runat="server" DataKeyNames="id" DataSourceID="AuthorsDataSource">
                     <ItemTemplate>
                        <asp:Panel runat="server" CssClass="ItemTemplatePanel">
                           <asp:LinkButton runat="server" ID="lbAddAuthor" CommandName="AddAuthorCommand" CausesValidation="false"
                              CommandArgument='<%# Eval("id") %>' OnCommand="AddAuthorButtonCommand"
                              Style="color: Black" Text='<%# ComposeFullName(Eval("authfn"),Eval("authmn"),Eval("authln")) %>'></asp:LinkButton>
                        </asp:Panel>
                     </ItemTemplate>
                     <AlternatingItemTemplate>
                        <asp:Panel runat="server" CssClass="ItemAlternateTemplatePanel">
                           <asp:LinkButton runat="server" ID="lbAddAuthor" CommandName="AddAuthorCommand" CausesValidation="false"
                              CommandArgument='<%# Eval("id") %>' OnCommand="AddAuthorButtonCommand"
                              Style="color: Black" Text='<%# ComposeFullName(Eval("authfn"),Eval("authmn"),Eval("authln")) %>'></asp:LinkButton>
                        </asp:Panel>
                     </AlternatingItemTemplate>
                     <EmptyDataTemplate>
                        <table runat="server" style="background-color: #FFFFFF; border-collapse: collapse;
                           border-color: #999999; border-style: none; border-width: 1px;">
                           <tr>
                              <td>
                                 <asp:Label runat="server" ID="EmptyDataLabel" Text="No result."></asp:Label>
                              </td>
                           </tr>
                        </table>
                     </EmptyDataTemplate>
                     <InsertItemTemplate>
                        <tr style="">
                           <td>
                              <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
                              <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
                           </td>
                           <td>
                              &nbsp;
                           </td>
                           <td>
                              <asp:TextBox ID="authfnTextBox" runat="server" Text='<%# Bind("authfn") %>' />
                           </td>
                           <td>
                              <asp:TextBox ID="authmnTextBox" runat="server" Text='<%# Bind("authmn") %>' />
                           </td>
                           <td>
                              <asp:TextBox ID="authlnTextBox" runat="server" Text='<%# Bind("authln") %>' />
                           </td>
                        </tr>
                     </InsertItemTemplate>
                     <LayoutTemplate>
                        <asp:Panel ID="itemPlaceholder" runat="server">
                        </asp:Panel>
                     </LayoutTemplate>
                     <EditItemTemplate>
                        <tr style="background-color: #999999;">
                           <td>
                              <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
                              <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
                           </td>
                           <td>
                              <asp:Label ID="idLabel1" runat="server" Text='<%# Eval("id") %>' />
                           </td>
                           <td>
                              <asp:TextBox ID="authfnTextBox" runat="server" Text='<%# Bind("authfn") %>' />
                           </td>
                           <td>
                              <asp:TextBox ID="authmnTextBox" runat="server" Text='<%# Bind("authmn") %>' />
                           </td>
                           <td>
                              <asp:TextBox ID="authlnTextBox" runat="server" Text='<%# Bind("authln") %>' />
                           </td>
                        </tr>
                     </EditItemTemplate>
                     <SelectedItemTemplate>
                        <tr style="background-color: #E2DED6; font-weight: bold; color: #333333;">
                           <td>
                              <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
                           </td>
                           <td>
                              <asp:Label ID="authfnLabel" runat="server" Text='<%# Eval("authfn") %>' />
                           </td>
                           <td>
                              <asp:Label ID="authmnLabel" runat="server" Text='<%# Eval("authmn") %>' />
                           </td>
                           <td>
                              <asp:Label ID="authlnLabel" runat="server" Text='<%# Eval("authln") %>' />
                           </td>
                        </tr>
                     </SelectedItemTemplate>
                  </asp:ListView>
               </asp:Panel>
               <asp:SqlDataSource ID="AuthorsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:NMRExperimentsConnectionString %>"
                  SelectCommand="SELECT        id, authfn, authmn, authln
FROM            authors
WHERE        (LEFT(authfn, @len) = @searchstr OR
                         LEFT(authmn, @len) = @searchstr OR
                         LEFT(authln, @len) = @searchstr) AND (NOT (authun = @username) OR
                         authun IS NULL) OR
                         (@len = 0) AND (NOT (authun = @username) OR
                         authun IS NULL)">
                  <SelectParameters>
                     <asp:Parameter DefaultValue="0" Name="len" />
                     <asp:Parameter DefaultValue="&quot;&quot;" Name="searchstr" />
                     <asp:Parameter DefaultValue="none" Name="username" />
                  </SelectParameters>
               </asp:SqlDataSource>
            </ContentTemplate>
            <Triggers>
            </Triggers>
         </asp:UpdatePanel>
      </asp:Panel>
      <act:CollapsiblePanelExtender ID="cpeSelectAuthorTable" runat="server"
         TargetControlID="panSelectAuthor" ExpandControlID="panAddNewAuthor"
         CollapseControlID="panAddNewAuthor" Collapsed="true">
      </act:CollapsiblePanelExtender>
   </asp:Panel>
</asp:Panel>
<act:RoundedCornersExtender ID="RoundedCornersExtender1" runat="server"
   TargetControlID="AuthorSelectionWrapper" Enabled="True" Color="#CEFF80"
   BorderColor="Black">
</act:RoundedCornersExtender>
